/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package loadUser;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import loadScore.Score;

/**
 *
 * @author usuario
 */
public class UserLoader implements UserManager{
    private String name;

    public UserLoader(String user) {
        this.name = "/Users/pedro/"+user+".txt";
    }

    @Override
    public void setLastLevel(int level) {
        FileOutputStream file=null;
        ObjectOutputStream out;
        try {
            file = new FileOutputStream(name);
            out = new ObjectOutputStream(file);
            out.writeObject(level);
            out.close();
            file.close();                 
            
        } catch (Exception ex) {
            try {
                Logger.getLogger(Score.class.getName()).log(Level.SEVERE, null, ex);
                if (file!=null)file.close();
            } catch (IOException ex1) {
                Logger.getLogger(UserLoader.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
    }

    @Override
    public int getLastLevel() {
        FileInputStream file;
        ObjectInputStream in;
        try{
            file = new FileInputStream(name);
            in = new ObjectInputStream(file);
            int num =(Integer)in.readObject();
            in.close();
            file.close();
            return num;
        }
        catch (Exception ex){
             Logger.getLogger(Score.class.getName()).log(Level.SEVERE, null, ex);
             return -1;
        }    
    }
    
}
